package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Employee;
import com.itheima.reggie.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.Local;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private RedisTemplate redisTemplate;
    @PostMapping("/login")
    public R<Employee> login(HttpServletRequest request, @RequestBody Employee employee)
    {
        R<Employee> result = employeeService.login(request, employee);
        return result;
    }
    @PostMapping("/logout")
    public R<String> logout(HttpServletRequest request)
    {
        R<String> result = employeeService.logout(request);
        return result;
    }
    @PostMapping
    public R<String>save(HttpServletRequest request, @RequestBody Employee employee)
    {
        return employeeService.save(request,employee);
    }
    @GetMapping("/page")
    public R<Page>page(int page,int pageSize,String name)
    {
        return employeeService.page(page,pageSize,name);
    }

    @PutMapping
    public R<String>update(HttpServletRequest request,@RequestBody Employee employee)
    {
        return employeeService.update(request,employee);
    }
    @GetMapping("/{id}")
    public R<Employee>getById(@PathVariable Long id)
    {
        return employeeService.myGetById(id);
    }
}
